﻿/*
	FlashBridge
	
	A proxy SWF to allow a Flex 2 SWF to run
	the adobe.utils.MMExecute class while in a Flash Panel
	in the Flash IDE.
	
    Created by Jesse R. Warden a.k.a. "JesterXL"
	jesterxl@jessewarden.com
	http://www.jessewarden.com
	
	This is release under a Creative Commons license. 
    More information can be found here:
    
    http://creativecommons.org/licenses/by/2.5/
*/
package
{
	import flash.display.MovieClip;
	import adobe.utils.MMExecute;
	
	public class FlashBridge extends MovieClip
	{
		
		protected var scope:Object;
		protected var callback:Function;
		
		public function FlashBridge()
		{
			super();
		}
		
		public function jsfl(p_str:String):String
		{
			var result:String = MMExecute(p_str);
			//runCallback(result);
			return result;
		}
		
		// this is needed for Flex to get return values from the jsfl function;
		// no idea why, maybe some security sandbox thing :: shrugs ::
		public function setCallback(p_scope:Object, p_callback:Function):void
		{
			scope = p_scope;
			callback = p_callback;
		}
		
		protected function runCallback(p_str:String):void
		{
			callback.call(scope, p_str);
		}
	}
}